package com.ling.rabbitmq.topic;

import lombok.SneakyThrows;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class TopicSender {

    @Autowired
    private AmqpTemplate amqpTemplate;

    public void send() {
        String context = "message all";
        System.out.println("Sender : " + context);
        amqpTemplate.convertAndSend("topicExchange", "topic.1", context);
    }

    @SneakyThrows
    public void send1() {
        String context = "message 1";
        System.out.println("Sender :" + context);
        this.amqpTemplate.convertAndSend("topicExchange", "topic.message", context);
        Thread.sleep(1000);
    }

    @SneakyThrows
    public void send2() {
        String context = "message 2";
        System.out.println("Sender :" + context);
        amqpTemplate.convertAndSend("topicExchange", "topic.messages", context);
        Thread.sleep(1000);
    }


}
